home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1990: Discy Business / Discy Business.2mg / DEV.CD / TOOLS / SAMPLES / HP / HP.ASM / INIT.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-03-24  |  15.7 KB  |  551 lines  |  [B0] Apple IIgs Source Code (0x0003)

  1.  
  2. ******************************************************************************
  3. *                                                                            *
  4. *         HodgePodge:  An example Apple IIGS Desktop application             *
  5. *                                                                            *
  6. *         Written in 65816 Assembler by the Apple IIGS Tools Team            *
  7. *  Modified by Ben Koning for "Programmer's Introduction to the Apple IIGS"  *
  8. *                                                                            *
  9. *             Copyright (c) 1986-87 by Apple Computer, Inc.                  *
  10. *                                                                            *
  11. *   ----------------------------------------------------------------------   *
  12. *                                                                            *
  13. *     ASM65816 Code file "INIT.ASM" -- Toolbox startup/shutdown routines     *
  14. *                                                                            *
  15. ******************************************************************************
  16.  
  17.  
  18.  
  19. *****************************************************************
  20. *
  21. * INIT.ASM
  22. *
  23. * Contains the following global data
  24. *
  25. *   MyID            Variable holding userid of this program
  26. *
  27. *   ThisMode        Variable holding mode used to start
  28. *                   QuickDraw
  29. *   OrigPort        Variable holding pointer to original
  30. *                   port that QuickDraw has when started up.
  31. *
  32. * Contains the following private data
  33. *
  34. *   ZPHandle        Holds handle to memory that is used
  35. *                   as direct page for the tools.
  36. *   ZPPtr           Pointer to above memory.
  37. *
  38. * Contains the following public procedures.
  39. *
  40. *   function  StartupTools  (ModeToUse : SCB_type) : integer;
  41. *
  42. *      Starts up the tools (initializing quickdraw with the specified
  43. *      mode) and initializes the global variables above.
  44. *
  45. *   procedure  ShutdownTools;
  46. *      Shuts things down, undoing what was done above.
  47. *
  48. * Uses the MountBootDisk dialog routine to have the user put the
  49. * system disk on line.
  50. *
  51. * Uses the CheckToolError dialog routine to cause a system death
  52. * (bouncing apple) if the A register is nonzero.  The X register is
  53. * assumed to contain a "Where" value.
  54. *
  55. * Change History
  56. *
  57. * June   1987  Steven E. Glass
  58. * August 1987  Ben Koning
  59. *
  60. * Modified to use the C calling convention so that can be used by
  61. * both C and TMLPascal.  (Input parameters are not removed from
  62. * the stack.)
  63. *
  64. *****************************************************************
  65.  
  66.  
  67. InitDummy      START
  68.  
  69.                COPY 7/E16.MEMORY
  70.  
  71.                END
  72.  
  73. ****************************************************************
  74. *
  75. * StartupTools
  76. *
  77. *     Input:    ModeToUse  -- $0080 for 640 mode
  78. *     Output:   ErrorCode  -- Error if nonzero
  79. *                             (NOTE: DIFFERENT FROM C AND PASCAL VERSIONS)
  80. *
  81. * Calling Sequence:
  82. *
  83. *         pha                ; space for output
  84. *         PushWord #Mode     ; Mode to use for QD
  85. *         jsl StartupTools
  86. *         plx                ; remove input parameter
  87. *         pla                ; get func result
  88. *         bne MustQuit
  89. *
  90. * This is a subroutine to load and startup all the tools
  91. * an application generally needs.  This routine also gets the
  92. * space in bank zero that the tools use for direct page.  The
  93. * only time an error code other than zero is returned is when
  94. * the boot disk is not on line and the user asks to cancel
  95. * rather than to put it on line.
  96. *
  97. * Order of work:
  98. *
  99. * 1)  Start
  100. *
  101. *      Tool Locator, Memory Manager, Misc Tools
  102. *      QuickDraw, Event Manager
  103. *
  104. * 2)  When these are running, the "One moment please" string is
  105. * displayed and LoadTools is called.
  106. *
  107. * QuickDraw and the Event Manager are started up first
  108. * because if the LoadTools call returns a VolNotFound error
  109. * we need to have the volume mounted.  This is done with
  110. * the TLMountVolume call which requires both QuickDraw and
  111. * the Event Manager to be active.
  112. *
  113. * 3)  Next I start up
  114. *
  115. *      Window Manager, Control Manager,
  116. *      Menu Manager, LineEdit, Dialog Manager
  117. *
  118. * 4)  After these are initialized, I setup and draw the
  119. * menu bar and display a message to the user before I
  120. * initialize the rest (Standard File, Font Manager,
  121. * QuickDraw Auxiliary and print manager).
  122. *
  123. ****************************************************************
  124. StartupTools   START
  125.                using InitData
  126.  
  127. ModeToUse      equ   $5
  128. ResultCode     equ   $7
  129.  
  130. ;-----------------------------------------------
  131. ;
  132. ; Direct Page use.  The following equates
  133. ; describe how the direct pages are assigned
  134. ; to the tools below.
  135. ;
  136. DPForQuickDraw equ $000                 ; needs 3
  137. DPForEventMgr  equ $300                 ; needs 1
  138. DPForCtlMgr    equ $400                 ; needs 1
  139. DPForLineEdit  equ $500                 ; needs 1
  140. DPForMenuMgr   equ $600                 ; needs 1
  141. DPForStdFile   equ $700                 ; needs 1
  142. DPForFontMgr   equ $800                 ; needs 1
  143. DPForPrintMgr  equ $900                 ; needs 2
  144.  
  145. TotalDP        equ $B00
  146.  
  147. ;-----------------------------------------------
  148. ;
  149. ; Just in case this routine is called when the
  150. ; data bank is set somewhere else we set it
  151. ; right here.
  152. ;
  153.                phb
  154.                phk
  155.                plb
  156.  
  157. ;-----------------------------------------------
  158. ;
  159. ; Copy the input parameter into the global
  160. ; data area and initialize the result code
  161. ; assuming all is well.
  162. ;
  163.                lda ModeToUse,s
  164.                sta ThisMode
  165.  
  166.                lda #0
  167.                sta ResultCode,s
  168.  
  169. ;-----------------------------------------------
  170. ;
  171. ; Start with TLStartup
  172. ;
  173.                _TLStartup               ; Tool Locator
  174.  
  175.  
  176. ;-------------------------------------------------
  177. ;
  178. ; Initialize the memory manager.
  179. ;
  180.  
  181.                PushWord #0
  182.                _MMStartup
  183.                ldx #1
  184.                jsr CheckToolError
  185.  
  186.                pla
  187.                sta MyID
  188.  
  189. ;-------------------------------------------------
  190. ;
  191. ; Initialize misc tools.
  192. ;
  193.                _MTStartup
  194.                ldx #2
  195.                jsr CheckToolError
  196.                
  197.  
  198. ;------------------------------------------------------
  199. ;
  200. ; First get some memory for the zero page we need!
  201. ;
  202.                pha                      ; space for handle
  203.                pha
  204.                PushLong #TotalDP
  205.                PushWord MyID
  206.                PushWord #attrBank+attrPage+attrFixed+attrLocked
  207.                PushLong #0
  208.                _NewHandle
  209.  
  210.                ldx #3
  211.                jsr CheckToolError
  212.                
  213.  
  214. ;-------------------------------------------------
  215. ;
  216. ; Take the resulting handle (still on the stack)
  217. ; and dereference it, putting the pointer into
  218. ; ZPPtr.
  219. ;
  220.                phd                      ; save current D
  221.                tsc                      ; turn stack into direct page
  222.                tcd
  223.                lda [3]                  ; deref the pointer
  224.                sta ZPPtr                ; we know that high word is 0
  225.                pld                      ; restore direct page
  226.  
  227.                pla                      ; put handle into storage
  228.                sta ZPHandle
  229.                pla
  230.                sta ZPHandle+2
  231.  
  232. ;-------------------------------------------------------------
  233. ;
  234. ; Note that width on startup is 320 to allow doubling the
  235. ; screen width when doing best printing.
  236. ;
  237.  
  238.                lda ZPPtr
  239.                clc
  240.                adc #DPForQuickDraw
  241.                pha
  242.                PushWord ThisMode
  243.                PushWord #320            ; max size of scan line in bytes
  244.                PushWord MyID
  245.                _QDStartup
  246.  
  247.                ldx #4
  248.                jsr CheckToolError
  249.                
  250.                PushLong #0
  251.                _GetPort
  252.                PullLong OrigPort 
  253.  
  254.                ldy #640
  255.                lda ThisMode
  256.                cmp #$80
  257.                beq okmode
  258.                ldy #320
  259. okmode         anop
  260.                sty MaxX
  261.  
  262.                lda ZPPtr
  263.                clc
  264.                adc #DPForEventMgr
  265.                pha
  266.                PushWord #20             ; queue size
  267.                PushWord #0              ; x clamp low
  268.                PushWord MaxX            ; x clamp high
  269.                PushWord #0              ; y clamp low
  270.                PushWord #200            ; y clamp high
  271.                PushWord MyID
  272.                _EMStartup
  273.  
  274.                ldx #5
  275.                jsr CheckToolError
  276.                
  277. ;-------------------------------------------------------
  278. ;
  279. ; Put up a string telling user that something is
  280. ; happening.
  281. ;
  282.                PushWord #20
  283.                PushWord #20
  284.                _MoveTo
  285.  
  286.                PushWord #0
  287.                _SetBackColor
  288.  
  289.                PushWord #$F
  290.                _SetForeColor
  291.  
  292.                PushLong #MomentStr
  293.                _DrawString
  294.  
  295.                _ShowCursor
  296.  
  297.  
  298. ;-------------------------------------------------------
  299. ;
  300. ; Make the LoadTools call
  301. ;
  302. LoadAgain      _GET_FILE_INFO ParamBlock       ;Try to find the directory
  303.                bcc OkToLoad                    ;*/SYSTEM/TOOLS/.  Ok? Go load.
  304.  
  305.                jsr MountBootDisk               ;Else, display psuedo-dialog
  306.                cmp #1                          ;Did they select "OK"?
  307.                beq LoadAgain                   ;Yes, so try it again.
  308.  
  309. ;                                              ;Else, they selected "Cancel".
  310.                sta ResultCode,s                ;So return result code
  311.                brl GetOut                      ;and leave this routine.
  312.  
  313. OkToLoad       PushLong #ToolTable             ;Push address of tool table
  314.                _LoadTools                      ;Attempt to load them (should
  315.                bcc ToolsLoaded                 ;work).  If ok, go on.
  316.  
  317.                ldx #6                          ;If error happened anyway,
  318.                jsr CheckToolError              ;we'll just die here.
  319.                
  320. ;------------------------------------------------------
  321. ;
  322. ; The tools are loaded so start them up.
  323. ;
  324. ToolsLoaded    anop
  325.                _QDAuxStartup            ; QuickDraw Auxiliary
  326.  
  327.                _WaitCursor              ; With QDAux started we can show the
  328. ;                                       ; watch cursor
  329.  
  330.                PushWord MyID            ; Window Manager
  331.                _WindStartup
  332.  
  333.                ldx #7
  334.                jsr CheckToolError
  335.                
  336.                PushLong #$0000          ; display desktop
  337.                _RefreshDeskTop
  338.  
  339.                PushWord MyID            ; Control Manager
  340.                lda ZPPtr
  341.                clc
  342.                adc #DPForCtlMgr
  343.                pha
  344.                _CtlStartup
  345.  
  346.                ldx #8
  347.                jsr CheckToolError
  348.                
  349.                PushWord MyID            ; LineEdit
  350.                lda ZPPtr
  351.                clc
  352.                adc #DPForLineEdit
  353.                pha
  354.                _LEStartup
  355.  
  356.                ldx #9
  357.                jsr CheckToolError
  358.  
  359.                PushWord MyID            ; Dialog Manager
  360.                _DialogStartup
  361.  
  362.                ldx #10
  363.                jsr CheckToolError
  364.                
  365.                PushWord MyID            ; Menu Manager
  366.                lda ZPPtr
  367.                clc
  368.                adc #DPForMenuMgr
  369.                pha
  370.                _MenuStartup
  371.  
  372.                ldx #11
  373.                jsr CheckToolError
  374.                
  375.                _DeskStartup             ; Desk Manager
  376.  
  377.                jsr ShowPleaseWait       ; Message for user
  378.  
  379.                ldx #12
  380.                jsr CheckToolError
  381.  
  382.                PushWord MyID            ; Standard File
  383.                lda ZPPtr
  384.                clc
  385.                adc #DPForStdFile
  386.                pha
  387.                _SFStartup
  388.  
  389.                ldx #13
  390.                jsr CheckToolError
  391.  
  392.                PushWord #$8000          ; display file names in all caps
  393.                _SFAllCaps
  394.  
  395.                PushWord MyID            ; Print Manager
  396.                lda ZPPtr
  397.                clc
  398.                adc #DPForPrintMgr
  399.                pha
  400.                _PMStartup
  401.  
  402.                ldx #14
  403.                jsr CheckToolError
  404.  
  405.                PushWord MyID            ; Font Manager
  406.                lda ZPPtr
  407.                clc
  408.                adc #DPForFontMgr
  409.                pha
  410.                _FMStartup
  411.  
  412.                ldx #15
  413.                jsr CheckToolError
  414.  
  415.                jsr HidePleaseWait
  416.  
  417.                _InitCursor              ; reset cursor to arrow cursor
  418.  
  419.  
  420. ;-------------------------------------------------------
  421. ;
  422. ; All is done.  We must clean up the stack and get out
  423. ;
  424. GetOut         anop
  425.                plb                      ; restore dbr
  426.                rtl                      ; all done.
  427.  
  428. MomentStr      str 'One moment please...'
  429.  
  430. MaxX           ds 2
  431.  
  432. ParamBlock     dc i4'PathName'          ;ProDOS/16 Parameter block
  433.                ds 2                     ;With pathname as input; rest of the
  434.                ds 2                     ;fields will be set as output.
  435.                ds  4
  436.                ds 2
  437.                ds 2
  438.                ds 2
  439.                ds 2
  440.                ds 2
  441.                ds  4
  442. PathName       str '*/SYSTEM/TOOLS'
  443.  
  444.                END
  445.  
  446.  
  447. *****************************************************************
  448. *
  449. * PublicInitData
  450. *
  451. * These are global variables available to the main program.
  452. *
  453. *****************************************************************
  454.  
  455. PublicInitDATA DATA ~Global
  456.  
  457. ;------------------------------------------------
  458. ;
  459. ; Public Variables
  460. ;
  461.  
  462. MyID           ENTRY
  463.                ds 2
  464.  
  465. ThisMode       ENTRY
  466.                ds 2
  467.  
  468. OrigPort       ENTRY
  469.                ds 2
  470.  
  471.                END
  472.  
  473.  
  474. InitData       PrivDATA
  475.  
  476. ZPHandle       ds 4
  477.  
  478. ZPPtr          ds 4
  479.  
  480. ToolTable      anop
  481. StartTable     anop
  482.                dc i'(EndTable-StartTable)/4'
  483.                dc i'1,$0101'            ; tool locator
  484.                dc i'2,$0101'            ; memory manager
  485.                dc i'3,$0101'            ; misc tools
  486.                dc i'4,$0101'            ; quickdraw
  487.                dc i'5,$0100'            ; desk manager
  488.                dc i'6,$0100'            ; event manager
  489.                dc i'14,$0103'           ; window manager
  490.                dc i'15,$0103'           ; menu manager
  491.                dc i'16,$0103'           ; control manager
  492.                dc i'18,$0100'           ; quickdraw aux
  493.                dc i'19,$0100'           ; print manager
  494.                dc i'20,$0100'           ; line edit
  495.                dc i'21,$0100'           ; dialog manager
  496.                dc i'22,$0102'           ; scrap manager
  497.                dc i'23,$0100'           ; standard file
  498.                dc i'27,$0100'           ; Font manager
  499.                dc i'28,$0100'           ; List manager
  500. EndTable       anop
  501.                END
  502.  
  503.  
  504.  
  505. ****************************************************************
  506. *
  507. * ShutDownTools
  508. *
  509. *   Inputs:   None
  510. *
  511. *   Outputs:  None
  512. *
  513. *
  514. * Shuts down every thing started up in InitTools
  515. *
  516. ****************************************************************
  517.  
  518. ShutDownTools  START
  519.                using InitData
  520.  
  521.  
  522.                _DeskShutdown            ; shut this first so that other tools
  523. ;                                       ; are still around (close DA's)
  524.                _FMShutDown
  525.                _PMShutdown
  526.                _SFShutDown
  527.                _DialogShutdown
  528.                _LEShutdown
  529.                _MenuShutDown
  530.                _WindShutDown
  531.                _CtlShutdown             ; this is shut down after window mgr
  532. ;                                       ; because window mgr makes contol
  533. ;                                       ; manager calls at shutdown time.
  534.  
  535.                _EMShutDown
  536.                _QDAuxShutdown
  537.                _QDShutDown
  538.                _MTShutdown
  539.  
  540.                PushLong ZPHandle        ; get rid of handle for direct
  541.                _DisposeHandle           ; page
  542.  
  543.                PushWord MyID
  544.                _MMShutdown
  545.  
  546.                _TLShutdown
  547.  
  548.                rtl
  549.  
  550.                END
  551.